import { fileURLToPath, URL } from 'node:url'
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      imports: ['vue'],
      resolvers: [
        ElementPlusResolver(),
      ],
      // 解决ElMessage等组件找不到的问题
      dts: 'src/auto-imports.d.ts',
    }),
    Components({
      resolvers: [ElementPlusResolver(
        {locale: zhCn}
      )],
    }),
  ],
  css:{
    preprocessorOptions:{
      scss:{
        additionalData: '@import "@/bem.scss";'
      }
    },
    postcss:{
      plugins:[
        tailwindcss,
        autoprefixer
      ]
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server:{
    port:5173,
    open:true,
    changeOrigin:true,
    proxy:{
      '/zym':{
        target:'http://localhost:3000',
        changeOrigin:true,
        rewrite:(path)=>path.replace(/^\/zym/, '')
      }
    }
  }
})
